-
Notifications
You must be signed in to change notification settings - Fork 1.9k
http_client: fix incomplete error handling in flb_http_do() #10810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add missing validation for flb_http_get_response_data() return value - Handle all possible return values from check_connection(): - FLB_HTTP_ERROR: propagate parsing errors - FLB_HTTP_NOT_FOUND: continue normally (valid per HTTP spec) - FLB_HTTP_OK: process connection close logic - Fix silent failures that could cause undefined behavior - Maintain full backward compatibility with existing callers Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
WalkthroughUpdates to src/flb_http_client.c modify error signaling, introduce a response reset helper, integrate it into request initialization, and refine control flow in flb_http_do for early error returns and explicit handling of Connection header outcomes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App
participant HTTP as flb_http_do_request
participant Client as flb_http_do
participant Conn as check_connection
App->>HTTP: start request
Note over HTTP: Initialize response state
HTTP->>HTTP: http_client_response_reset(c)
HTTP->>Client: send/receive loop
Client->>Client: process response data
alt processing error
Client-->>HTTP: ret != FLB_HTTP_OK
HTTP-->>App: return error (early)
else processing ok
Client->>Conn: check_connection(headers)
alt Conn == FLB_HTTP_ERROR
Client-->>HTTP: error
HTTP-->>App: return error
else Conn == FLB_HTTP_OK
Note over Client: Preserve keepalive/close logic
Client-->>HTTP: continue
HTTP-->>App: success
else Conn == FLB_HTTP_NOT_FOUND
Note over Client: No-op path (explicit)
Client-->>HTTP: continue
HTTP-->>App: success
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/flb_http_client.c (3)
243-260: OOM now returns FLB_HTTP_ERROR; add bounds check to avoid over-read in strncasecmpGood call switching OOM to FLB_HTTP_ERROR for consistent signaling. Minor safety nit: guard the "close" compare to avoid reading past the buffer when len < 5.
Apply:
@@ - if (strncasecmp(buf, "close", 5) == 0) { + if (len >= 5 && strncasecmp(buf, "close", 5) == 0) { c->resp.connection_close = FLB_TRUE; }
268-279: Reset helper is solid; also null-terminate the response buffer headResetting all response fields centrally is great. Consider setting data[0] to '\0' to avoid any accidental stale scans before the first read.
Apply:
static inline void http_client_response_reset(struct flb_http_client *c) { c->resp.data_len = 0; + if (c->resp.data) { + c->resp.data[0] = '\0'; + } c->resp.status = 0; c->resp.content_length = -1; c->resp.chunked_encoding = FLB_FALSE; c->resp.connection_close = -1; c->resp.headers_end = NULL; c->resp.payload = NULL; c->resp.payload_size = 0; c->resp.chunk_processed_end = NULL; }
1565-1585: Explicit tri-state handling of Connection header improves robustness; consider defensive ‘MORE’ case or switchHandling ERROR/OK/NOT_FOUND explicitly is good. Since check_connection theoretically can return FLB_HTTP_MORE only when headers are incomplete, which shouldn’t happen post-OK, you may add a debug-only guard (or switch) for clarity.
Example:
- ret = check_connection(c); + ret = check_connection(c); if (ret == FLB_HTTP_ERROR) { return ret; } - else if (ret == FLB_HTTP_OK) { + else if (ret == FLB_HTTP_OK) { ... } else if (ret == FLB_HTTP_NOT_FOUND) { /* Connection header not found, continue normally */ } + /* Unexpected here, but keep a defensive branch for readability */ + /* else if (ret == FLB_HTTP_MORE) { */ + /* flb_debug("[http_client] connection header incomplete after full response"); */ + /* } */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/flb_http_client.c(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
- GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_ARROW=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
- GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-24.04, clang-14)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, clang, clang++, ubuntu-22.04, clang-12)
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-22.04, clang-12)
- GitHub Check: PR - fuzzing test
- GitHub Check: pr-compile-system-libs (-DFLB_PREFER_SYSTEM_LIBS=On, 3.31.6, gcc, g++, ubuntu-24.04, clang-14)
- GitHub Check: pr-compile-centos-7
🔇 Additional comments (3)
src/flb_http_client.c (3)
1434-1435: Good: use the centralized reset before reading responseThis eliminates partial-state carryover between requests.
1550-1556: Helpful inline rationale for bytes_consumed=0 in flb_http_doComment clarifies the contract for chunked handling here.
1559-1562: Early return on non-OK cleans up control flow and propagates errorsPrevents silent fallthrough on malformed/incomplete responses.
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit